package com.xqb.modules.controller.market;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.MktCoupon;
import com.xqb.modules.service.IMktCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券的规则信息Controller
 * 
 * @author xqb
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/market/coupon")
public class MktCouponController extends BaseController
{
    @Autowired
    private IMktCouponService mktCouponService;

    /**
     * 查询优惠券的规则信息列表
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(MktCoupon mktCoupon)
    {
        startPage();
        List<MktCoupon> list = mktCouponService.selectMktCouponList(mktCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠券的规则信息列表
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:export')")
    @Log(title = "优惠券的规则信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MktCoupon mktCoupon)
    {
        List<MktCoupon> list = mktCouponService.selectMktCouponList(mktCoupon);
        ExcelUtil<MktCoupon> util = new ExcelUtil<MktCoupon>(MktCoupon.class);
        util.exportExcel(response, list, "优惠券的规则信息数据");
    }

    /**
     * 获取优惠券的规则信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mktCouponService.selectMktCouponById(id));
    }

    /**
     * 新增优惠券的规则信息
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:add')")
    @Log(title = "优惠券的规则信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MktCoupon mktCoupon)
    {
        return toAjax(mktCouponService.insertMktCoupon(mktCoupon));
    }

    /**
     * 修改优惠券的规则信息
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:edit')")
    @Log(title = "优惠券的规则信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MktCoupon mktCoupon)
    {
        return toAjax(mktCouponService.updateMktCoupon(mktCoupon));
    }

    /**
     * 删除优惠券的规则信息
     */
    @PreAuthorize("@ss.hasPermi('market:coupon:remove')")
    @Log(title = "优惠券的规则信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mktCouponService.deleteMktCouponByIds(ids));
    }
}
